<!-- 交易控制 -->
<template>
	<section>
		<!--列表-->
		<el-form label-width="80px">
			<el-form-item label="发单量" prop="price">
				<el-input v-model="List.quantity" auto-complete="off"></el-input>
				<el-button type="primary" size="small" @click="submit(1)" style="margin-top: 10px;">确定</el-button>
			</el-form-item>
			<el-form-item label="交易额" prop="price">
				<el-input v-model="List.tradeNum" auto-complete="off"></el-input>
				<el-button type="primary" size="small" @click="submit(2)" style="margin-top: 10px;">确定</el-button>
			</el-form-item>
		</el-form>
		<el-col :span="24" class="toolbar">
			<div class="title">
				<div class="title_left">
					<p class="title_text">交易开关：</p>
					<el-button  v-if="List.istrueTotal == '0'" type="danger" size="small" @click="handleOpen(1)">关闭交易</el-button>
					<el-button v-else-if="List.istrueTotal == '1'" type="success" size="small" @click="handleOpen(0)">开放交易</el-button>
				</div>
				<div class="title_left">
					<p class="title_text">买卖开关：</p>
					<el-button  v-if="List.istrue == '0'" type="danger" size="small" @click="handleswitch(1)">关闭买卖</el-button>
					<el-button v-else-if="List.istrue == '1'" type="success" size="small" @click="handleswitch(0)">开放买卖</el-button>
				</div>
			</div>
		</el-col>
		<el-col :span="24" class="toolbar">
			<div style="display: flex;align-items: center;justify-content: space-between;">
				<div class="title_left">
					<p class="title_text">1区是否显示订单：</p>
					<el-button  v-if="value.config_1 == '0'" type="danger" size="small" @click="handleconfig(1,1)">关闭</el-button>
					<el-button v-else-if="value.config_1 == '1'" type="success" size="small" @click="handleconfig(1,0)">开放</el-button>
				</div>
				<div class="title_left">
					<p class="title_text">2区是否显示订单：</p>
					<el-button  v-if="value.config_2 == '0'" type="danger" size="small" @click="handleconfig(2,1)">关闭</el-button>
					<el-button v-else-if="value.config_2 == '1'" type="success" size="small" @click="handleconfig(2,0)">开放</el-button>
				</div>
				<div class="title_left">
					<p class="title_text">3区是否显示订单：</p>
					<el-button  v-if="value.config_3 == '0'" type="danger" size="small" @click="handleconfig(3,1)">关闭</el-button>
					<el-button v-else-if="value.config_3 == '1'" type="success" size="small" @click="handleconfig(3,0)">开放</el-button>
				</div>
				<div class="title_left">
					<p class="title_text">4区是否显示订单：</p>
					<el-button  v-if="value.config_4 == '0'" type="danger" size="small" @click="handleconfig(4,1)">关闭</el-button>
					<el-button v-else-if="value.config_4 == '1'" type="success" size="small" @click="handleconfig(4,0)">开放</el-button>
				</div>
			</div>
		</el-col>
	</section>
</template>
<script>
	import util from '../../../common/js/util'
	import {
		getUserSys,
		editUserSys,
		getConfigList,
		editConfigList,
		Refreshtoken
	} from '../../../api/api';
	
	export default {
		data() {
			return {
				timer: null,
				total: 0,
				page: 1,
				sels: [],//列表选中列
				loading: false,
				List:{},
				value:'',
			}
		},
		mounted() {
			this.getPriceList()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
			}, 600000)
		},
		methods: {
			getPriceList(){
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				var para = {
					token: Token,
					timestamp: timestamp
				};
				this.loading = true;
				getUserSys(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.List = res.data;
						this.loading = false;
					}
				});
				getConfigList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.value = res.data;
						this.loading = false;
					}
				});
			},
			// 刷新token
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			submit(type){
				if(type == '1'){
					this.$confirm('确认修改发单量吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,quantity:this.List.quantity};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}else if(type == '2'){
					this.$confirm('确认修改交易额吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,tradeNum:this.List.tradeNum};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}
			},
			//修改设置
			handleOpen(type){
				if(type == '0'){
					this.$confirm('确认开放交易吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,tradeNum:this.List.tradeNum,istrueTotal:type};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}else if(type == '1'){
					this.$confirm('确认关闭交易吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,tradeNum:this.List.tradeNum,istrueTotal:type};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}
				
			},
			handleswitch(type){
				if(type == '0'){
					this.$confirm('确认开放买卖吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,quantity:this.List.quantity,istrue:type};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}else if(type == '1'){
					this.$confirm('确认关闭买卖吗？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp=new Date().getTime();
						var para = {token: Token,timestamp:timestamp,quantity:this.List.quantity,istrue:type};
						editUserSys(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.getPriceList()
							}
						});
					});
				}
				
			},
			//开关
			handleconfig(type,index){
				if (type == '1') {
					if(index == '0'){
						this.$confirm('确认开放吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_1:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}else if(index == '1'){
						this.$confirm('确认关闭吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_1:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}
				} else if(type == '2'){
					if(index == '0'){
						this.$confirm('确认开放吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_2:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}else if(index == '1'){
						this.$confirm('确认关闭吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_2:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}
				}else if(type == '3'){
					if(index == '0'){
						this.$confirm('确认开放吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_3:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}else if(index == '1'){
						this.$confirm('确认关闭吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_3:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}
				}else if(type == '4'){
					if(index == '0'){
						this.$confirm('确认开放吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_4:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}else if(index == '1'){
						this.$confirm('确认关闭吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {token: Token,timestamp:timestamp,config_4:index};
							editConfigList(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.getPriceList()
								}
							});
						});
					}
				}
			}
		},
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.title{
	display:flex;
	align-items:center;
	justify-content: flex-end;
}
.title_left{
	display:flex;
	align-items:center;
	justify-content:center;
	margin-right: 15px;
}
.title_text{
	font-size:16px;
}
</style>
